package net.sevear.chaos.p2p
{
	import de.popforge.utils.SprintfUtil;
	
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import net.sevear.chaos.vo.DoubanAlbumInfo;
	import net.sevear.chaos.vo.UserInfo;

	public class DBCollectionOfflineSourcer extends P2POffLineSource
	{
		private static const COLLECTION_URL:String = "http://music.douban.com/people/%S/collect?sort=rating&start=%d&mode=grid&tags_sort=count";
		
		private static const COLLECTION_PAGE_SIZE:int = 15;
		
		private var fiveStartAlbums:Array;
		private var _dbUID:String;
		private var curRequestPageId:int;
		private var loader:URLLoader;
		private var isSendingRequest:Boolean = false;
		
		public function DBCollectionOfflineSourcer()
		{
			super();
			
		}
		
		override public function init(user:UserInfo):void{
			_dbUID = user.dbUID;
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE,onLoadCollectionPageComplete);
			loader.addEventListener(IOErrorEvent.IO_ERROR,onLoadIOError);
			
			requestList();
		}
		
		override public function getList(lastPlayID:int):Array{
			return null;
		}
		
		//TODO:
		override public function requestList():void{
			if(isSendingRequest==false){
				var url:String = SprintfUtil.sprintf(COLLECTION_URL,_dbUID,curRequestPageId*COLLECTION_PAGE_SIZE);
				isSendingRequest = true;
				loader.load(new URLRequest(url));
			}
		}
		
		private function onLoadCollectionPageComplete(e:Event):void{
			isSendingRequest = false;
			//TODO:PARSE THE HTML
			
		}
		
		private function onLoadIOError(e:IOErrorEvent):void{
			isSendingRequest = false;
		}
		
	}
}